<template>
	<!-- 面试题列表 -->
	<view class="topic">
		<view class="title">{{text}}面试题</view>
		<topic-item :data="arr" v-if="arr.length != 0"></topic-item>
		<view class="message" v-else>暂无面试题~~</view>
	</view>
</template>

<script>
	import TopicItem from '../../components/TopicItem/TopicItem'

	// 选项式开发
	export default {
		components: {
			TopicItem
		},
		data() {
			return {
				arr: [],
				text: ""
			}
		},
		onLoad(options) {
			console.log(options);
			let {
				text
			} = options;
			if (text) {
				this.getInterviewListFn(text);
				this.text = text;
			}
		},
		methods: {
			async getInterviewListFn(value) {
				await uniCloud.callFunction({
						name: 'interview',
						data: {
							text: value
						}
					})
					.then(
						resData => {
							console.log(resData)
							if (resData.result && resData.result.data) {
								let data = resData.result.data;
								this.arr = data;
								// 把分类面试题列表存储在本地
								uni.setStorageSync("INTERVIEW", data);
							}
						}
					)
					.catch(err => {
						console.log(err)
					})
			}
		}
	}
</script>

<style lang="scss">
	@import "../../static/scss/variable.scss";

	.topic {
		padding: $padd;
	}
</style>